import request from '@/config/axios'
import { defHttp } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import { ServicePrefixEnum } from '@/enums/commonEnum';
import type { AxiosRequestConfig } from 'axios';

const MODULAR = '/system/user/profile';

export const Api = {
  GetUserProfile: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  UpdateUserProfile: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  UpdateUserPassword: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update-password`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
}


// 查询用户个人信息
export const getUserProfile = () => {
  return defHttp.request({ ...Api.GetUserProfile})
}

// 修改用户个人信息
export const updateUserProfile = (data: UserProfileUpdateReqVO) => {
  return defHttp.request({ ...Api.UpdateUserProfile,params:data})
}

// 用户密码重置
export const updateUserPassword = (oldPassword: string, newPassword: string) => {
  let params = {data:{
      oldPassword: oldPassword,
      newPassword: newPassword
    }}
  return defHttp.request({ ...Api.UpdateUserProfile,params:params})
}

export interface ProfileVO {
  id: number
  username: string
  nickname: string
  dept: {
    id: number
    name: string
  }
  roles: {
    id: number
    name: string
  }[]
  posts: {
    id: number
    name: string
  }[]
  socialUsers: {
    type: number
    openid: string
  }[]
  email: string
  mobile: string
  sex: number
  avatar: string
  status: number
  remark: string
  loginIp: string
  loginDate: Date
  createTime: Date
}

export interface UserProfileUpdateReqVO {
  nickname: string
  email: string
  mobile: string
  sex: number
}

// 查询用户个人信息
// export const getUserProfile = () => {
//   return request.get({ url: '/system/user/profile/get' })
// }
//
// // 修改用户个人信息
// export const updateUserProfile = (data: UserProfileUpdateReqVO) => {
//   return request.put({ url: '/system/user/profile/update', data })
// }
//
// // 用户密码重置
// export const updateUserPassword = (oldPassword: string, newPassword: string) => {
//   return request.put({
//     url: '/system/user/profile/update-password',
//     data: {
//       oldPassword: oldPassword,
//       newPassword: newPassword
//     }
//   })
// }

// 用户头像上传 todo
export const uploadAvatar = (data) => {
  return request.upload({ url: '/system/user/profile/update-avatar', data: data })
}
